package deadlock1;

import java.util.concurrent.CountDownLatch;

public class main {

    /**
     * 在多线程环境下，如果有多个线程同时去初始化同一个类，那么JVM会确保只有一个线程能够真正执行这个类的初始化代码块（<clinit>()方法）
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch cdl = new CountDownLatch(2);
        new Thread(() -> {
            MyParent myParent = new MyParent();
            cdl.countDown();
        }, "parent thread").start();
        new Thread(() -> {
            MyChild myChild = new MyChild();
            cdl.countDown();
        }, "child thread").start();
        cdl.await();
    }

}
